package com.sxm.yiwei.adapters;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.MineMsgHead;
import com.sxm.yiwei.beans.DiscussBeans;
import com.sxm.yiwei.tools.CastTime;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.x;

import java.util.HashMap;
import java.util.List;

/**
 * Created by KuKa on 2017/7/15.
 * 评论列表
 */

public class FWDiscussAdapter extends BaseAdapter {
    Context context;
    List<DiscussBeans.DataBean> mlist;
    public FWDiscussAdapter(Context context, List<DiscussBeans.DataBean> mlist) {
        this.context=context;
        this.mlist= mlist;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context, R.layout.discuss_list_item,null);
            holder = new ViewHolder();
            holder.head = (ImageView) view.findViewById(R.id.dis_listhead);
            holder.grade = (ImageView) view.findViewById(R.id.dis_list_grade);
            holder.grade1 = (ImageView) view.findViewById(R.id.dis_list_grade1);
            holder.grade2 = (ImageView) view.findViewById(R.id.dis_list_grade2);
            holder.grade3 = (ImageView) view.findViewById(R.id.dis_list_grade3);
            holder.grade4 = (ImageView) view.findViewById(R.id.dis_list_grade4);
            holder.name = (TextView) view.findViewById(R.id.dis_listname);
            holder.time = (TextView) view.findViewById(R.id.dis_listtime);
            holder.listcontent = (TextView) view.findViewById(R.id.dis_listcontent);
            holder.contentpic = (GridView) view.findViewById(R.id.dis_listcontentpic);
            view.setTag(holder);
        }else {
            view= convertView;
            holder= (ViewHolder) view.getTag();
        }

        DiscussBeans.DataBean dataBean = mlist.get(position);
        holder.time.setText(CastTime.CastTime(mlist.get(position).getCreateTime()));
        holder.name.setText(mlist.get(position).getNickname());
        holder.listcontent.setText(mlist.get(position).getContent());
        int score = mlist.get(position).getScore();
        switch (score){
            case 1:
                holder.grade.setImageResource(R.mipmap.fabupingjia2);

                break;
            case 2:
                holder.grade.setImageResource(R.mipmap.fabupingjia2);
                holder.grade1.setImageResource(R.mipmap.fabupingjia2);
                break;
            case 3:
                holder.grade.setImageResource(R.mipmap.fabupingjia2);
                holder.grade1.setImageResource(R.mipmap.fabupingjia2);
                holder.grade2.setImageResource(R.mipmap.fabupingjia2);
                break;
            case 4:
                holder.grade.setImageResource(R.mipmap.fabupingjia2);
                holder.grade1.setImageResource(R.mipmap.fabupingjia2);
                holder.grade2.setImageResource(R.mipmap.fabupingjia2);
                holder.grade3.setImageResource(R.mipmap.fabupingjia2);
                break;
            case 5:
                holder.grade.setImageResource(R.mipmap.fabupingjia2);
                holder.grade1.setImageResource(R.mipmap.fabupingjia2);
                holder.grade2.setImageResource(R.mipmap.fabupingjia2);
                holder.grade3.setImageResource(R.mipmap.fabupingjia2);
                holder.grade4.setImageResource(R.mipmap.fabupingjia2);
                break;
        }

        Picasso.with(context).load(InternetAddressUtis.IMG_URL+ mlist.get(position).getUserAvatar()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(holder.head);

      //  x.image().bind(holder.head, InternetAddressUtis.IMG_URL+mlist.get(position).getUserAvatar());
        List<?> commentImage = mlist.get(position).getCommentImage();
        if (commentImage==null){

        }else {
            FwDiscussGridAdapter gridAdapter = new FwDiscussGridAdapter(context,mlist.get(position).getCommentImage());
            holder.contentpic.setAdapter(gridAdapter);
        }


        notifyDataSetChanged();
        return view;
    }
    class ViewHolder{
        ImageView head,grade,grade1,grade2,grade3,grade4;
        TextView name,time,listcontent;
        GridView contentpic;
    }
}
